<?php
class OrgRackRelation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organizations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'organization_racks';
	}
	
	public function relations()
	{
		return array(
			'organization'=>array(self::BELONGS_TO, 'Organizations', 'organization_ID'),
			'rack'=>array(self::BELONGS_TO, 'Racks', 'rack_ID'),
		);
	}
	
	// returns true if rack exists with organization
	public function hasRack($userID, $rackID) {
		$sql = "SELECT * FROM ".$this->tableName()." where organization_ID='" . Users::model()->getOrganizationID($userID) . "'"
					. " and rack_ID='" . $rackID . "'";
		$rack = $this->findAllBySql($sql);
		
		if (empty($rack))
			return false;
		else
			return true;
	}
}
?>